package co.baiku.boot.web.controller;

import co.baiku.boot.common.message.Message;
import co.baiku.boot.common.validate.Validation;
import co.baiku.boot.core.web.controller.BaseController;
import co.baiku.boot.job.model.QuartzJobInfo;
import co.baiku.boot.job.service.QuartzJobService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/job")
public class JobController extends BaseController {
    @Resource
    private QuartzJobService quartzJobService;

    @GetMapping("/add")
    public Message add(QuartzJobInfo jobInfo) {
        Validation.assertSuccess(jobInfo);
        quartzJobService.addJob(jobInfo);
        return Message.success();
    }

    @GetMapping("/delete")
    public Message delete(QuartzJobInfo jobInfo) {
        quartzJobService.delete(jobInfo.getJobName(), jobInfo.getJobGroup());
        return Message.success();
    }

    @GetMapping("/list")
    public Message list() {
        List<QuartzJobInfo> list = quartzJobService.list();
        return Message.result(list);
    }

}
